package com.tedu.utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.beans.PropertyVetoException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

public class DataSource  {
    private static ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
    private static Properties properties = new Properties();
    static {

        try {
            properties.load(DataSource.class.getResourceAsStream("/c3p0-config.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static Connection getConnection()  {
        Connection conn =  null;
        try {
            comboPooledDataSource.setDriverClass(properties.getProperty("driverClass"));
            comboPooledDataSource.setJdbcUrl(properties.getProperty("jdbcUrl"));
            comboPooledDataSource.setUser(properties.getProperty("user"));
            comboPooledDataSource.setPassword(properties.getProperty("password"));
            conn = comboPooledDataSource.getConnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
        

        return conn;

    }

}
